package simple

var m = map[rune]rune{
	')': '(',
	'}': '{',
	']': '[',
}

func isValid(s string) bool {
	var stack []rune
	for _, ch := range s {
		v, ok := m[ch]
		if !ok {
			stack = append(stack, ch)
			continue
		}
		if len(stack) == 0 {
			return false
		}
		r := stack[len(stack)-1]
		if r != v {
			return false
		}
		stack = stack[:len(stack)-1]
	}

	return len(stack) == 0
}
